/*
 * Worker.h
 *
 *  Created on: Nov 17, 2008
 *      Author: Ryan
 */

#ifndef WORKER_H_
#define WORKER_H_

#include "WorkPool.h"

#include "../../../OOInterface/Objects/Logger.h"
#include <exception>

class Worker
{
public:
	Worker( WorkPool* pool ): work( pool ) {}
	virtual ~Worker() {}

	void run()
	{
		while(true)
		{
			try {
				work->getWorkUnit()->run();
			}
			catch( ... )
			{
				OOInterface::Logger::getInstance("AI.txt") << "Worker had an exception on a work unit!" << std::endl;
			}

			OOInterface::Logger::getInstance("AI.txt") << "Worker completed a work unit!" << std::endl;
		}
	}

private:
	WorkPool* work;
};

#endif /* WORKER_H_ */
